const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        goodsDetail: 'goodsDetail',
        servers: [
            {
                text: '15天无忧退货'
            },
            {
                text: '假一赔十'
            },
            {
                text: '48小时快速退款'
            },
            {
                text: '黑卡会员免邮'
            },
            {
                text: '太平洋承保'
            }
        ],
        serversModal: [
            {
                text: '15天无忧退货',
                dec: '自收到商品之日起15天内，可在线申请无忧退换货服务（食品、贴身衣物、积分兑换等特殊商品除外）。'
            },
            {
                text: '假一赔十',
                dec: '简选每一件商品都通过严苛的品质把关，保障正品，保障品质。特推岀“假一赔十”的正品保障政策，由太平洋保险承保，杜绝一切假货，让您无忧购物。'
            },
            {
                text: '48小时快速退款',
                dec: '收到退货包裹并确认无误后，将在48小时内办理退款，退款将原路返回，不同银行处理时间不同，预计1-5个工作日到账。'
            },
            {
                text: '黑卡会员免邮',
                dec: '简选黑卡会员全场商品包邮'
            },
            {
                text: '太平洋承保',
                dec: '简选每一件商品都通过严苛的品质把关，由太平洋保险承保，保障正品,保障品质，让您购物无忧。'
            }
        ],
        imgUrls: [
            'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?h=' + parseInt(320 * app.globalData.rpxToPxBl),
            'https://images.unsplash.com/photo-1551214012-84f95e060dee?h=' + parseInt(320 * app.globalData.rpxToPxBl),
            'https://images.unsplash.com/photo-1551446591-142875a901a1?h=' + parseInt(320 * app.globalData.rpxToPxBl),
        ],
        current: 0,
        taps: [
            {
                text: "猜你会喜欢",
                type: 1
            },
            {
                text: "大家都在买",
                type: 2
            }
        ],
        curTap: 1,
        scroolLeft: 0,
        chooseShowModal: false,
        maskShowModel: false,
        serverModal: false,
        couponsModal: false,
        shareModal: false,
        spcOneItems: [
            {
                value: '黑色',
                id: 1
            },
            {
                value: '白色',
                id: 2
            },
            {
                value: '藏青色',
                id: 3
            },
            {
                value: '玛瑙黑色',
                id: 4
            },
            {
                value: '粉红色',
                id: 5
            },
        ],
        spcOne: '',
        spcTwoItems: [
            {
                value: 'S',
                id: 1
            },
            {
                value: 'M',
                id: 2
            },
            {
                value: 'L',
                id: 3
            },
            {
                value: 'XL',
                id: 4
            },
            {
                value: 'XXL',
                id: 5
            },
        ],
        spcTwo: '',
        chooseNum: 1, //商品加入购物车的数量
        scrollTop: 0,
        goodsBlockScroolTop: 0,
        detailsBlockScroolTop: 0,
        anchorType: 0,
        info: {
            minPrice: 1,
            maxPrice: 2
        },
        type: 0,//显示是抢购还是普通商品详情,0 抢购详情,1 普通商品详情
      shrinkIndex: undefined,  //优惠券index
      isFolded: true,
      getCouponsFlag:false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      wx.hideShareMenu()
        var that = this;
        var type = options.type;
        that.setData({
            type: type
        })
        var query = wx.createSelectorQuery();
        query.select("#goodsBlock").boundingClientRect(function (res) {
            console.log('goodsScroll', res.top)
            that.setData({
                goodsBlockScroolTop: res.top
            })
        }).exec()
        query.select("#detailsBlock").boundingClientRect(function (res) {
            console.log('detailsScroll', res.top)
            that.setData({
                detailsBlockScroolTop: res.top
            })
        }).exec()
    },
    tapSelected: function (e) {
        let that = this;
        let curType = e.currentTarget.dataset.type;
        that.setData({
            curTap: curType,
            scroolLeft: (curType - 1) * 60
        })
    },

    //   选择第一个规格
    chooseSpcOne: function (e) {
        this.setData({
            spcOne: e.currentTarget.dataset.value
        })
    },
    //   选择第二个规格
    chooseSpcTwo: function (e) {
        this.setData({
            spcTwo: e.currentTarget.dataset.value
        })
    },

    numLow: function () {
        var that = this;
        var num = this.data.chooseNum;
        if (num > 1) {
            num--
        }
        that.setData({
            chooseNum: num
        })
    },
    numAdd: function () {
        var that = this;
        var num = this.data.chooseNum;
        num++;
        that.setData({
            chooseNum: num
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function (options) {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },
    onPageScroll: function (e) {
        this.setData({
            scrollTop: e.scrollTop
        })
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    swiperChange: function (e) {
        this.setData({
            current: e.detail.current
        })
    },
    back: function () {
        wx.navigateBack();
    },
    //  弹出选择弹窗
    chooseSpe: function () {
        this.setData({
            chooseShowModal: true,
            maskShowModel: true
        })
    },
    showServerModal: function () {
        this.setData({
            serverModal: true,
            maskShowModel: true
        })
    },
    showCouponsModal: function () {
        this.setData({
            couponsModal: true,
            maskShowModel: true
        })
    },
    hiddenModels: function () {
        this.setData({
            chooseShowModal: false,
            maskShowModel: false,
            serverModal: false,
            couponsModal: false,
            shareModal: false
        })
    },
    showShareModal: function () {
        this.setData({
            shareModal: true,
            maskShowModel: true
        })
    },
    // 设置锚点
    goodsBlock: function (e) {
        var type = e.currentTarget.dataset.type;
        this.setData({
            anchorType: type
        })
        wx.pageScrollTo({
            scrollTop: this.data.goodsBlockScroolTop, // 目标位置
        });
    },
    detailsBlock: function (e) {
        var type = e.currentTarget.dataset.type;
        this.setData({
            anchorType: type
        })
        wx.pageScrollTo({
            scrollTop: this.data.detailsBlockScroolTop
        })
    },
    toEvaluate: function () {
        wx.navigateTo({
            url: '../goods-evaluate/index' // 指定页面的url
        });
    },
  toBrandIndex:function(){
    wx.navigateTo({
      url: '../brand-index/brand-index',
    })
  },
  toPingDetail:function(){
    wx.navigateTo({
      url: '../ping-detail/ping-detail',
    })
  },
  toMainCart:function(){
    wx.switchTab({
      url:'../main-cart/main-cart'
    })
  },
  shrink: function (e) {
    var index = e.currentTarget.dataset.index;
    console.log('展开')
    this.setData({
      shrinkIndex: index,
      isFolded: !this.data.isFolded
    })
  },
  kefuContact:function(e){
    
  }

})